package logic

import (
	"context"
	"user_srv/user"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHouseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddLogic {
	return &HouseAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HouseAddLogic) HouseAdd(req *types.HouseAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.UserSrv.HouseAdd(l.ctx, &user.HouseAddRequest{
		UserId:        req.UserId,
		HouseName:     req.HouseName,
		HouseFloor:    req.HouseFloor,
		HouseType:     req.HouseType,
		Address:       req.Address,
		HouseCover:    req.HouseCover,
		Area:          req.Area,
		Price:         req.Price,
		HouseDescribe: req.HouseDescribe,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "我的房源发布成功",
		Data: map[string]interface{}{
			"Add": add.HouseId,
		},
	}, nil
}
